<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Translate css to javascript string</title>	
</head>
	
<body>
<textarea cols="80" rows="15" id="csscode"></textarea>
<br/>
<button onclick="translate()">translate</button>
<br/>
<textarea cols="80" rows="15" id="jscode"></textarea>
<script type="text/javascript">
	function $(s){
		return document.getElementById(s);
		}
	function wrapLine(s){
		var ret = s;
		var rep = /(['\\])/g;
		var rep1 = /\\/g;
		var ore = /\t/g;
		ret = ret.replace(rep,'\\$1');
		ret = ret.replace(ore,'    ');
		ret = "'" + ret + "'";
		return ret;
		}	
	function translate(){
		var css = $('csscode').value;
		if(!css){
			return false;
			}
		var trim = /^\s+|\s+$/g	
		css = css.replace(trim,'');	
		var lines = css.split(/[\r\n]/g);
		var line = '';
		var tmpArr = [];
		for(var i=0,ilen=lines.length;i<ilen;i++){
			line = wrapLine(lines[i]);
			tmpArr.push(line);
			}
		var ret = tmpArr.join(',\r\n');
		ret = '[' + ret + "].join('\\r\\n');";
		$('jscode').value = ret;	
		//alert(lines.length);
		}
</script>
</body>

</html>